package com.chengdu.his.sys.service.impl;

import com.chengdu.his.pojo.Role;
import com.chengdu.his.sys.mapper.RoleMapper;
import com.chengdu.his.sys.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    private RoleMapper roleMapper;

    @Override
    public int add(Role role) throws Exception {
        return roleMapper.add(role);
    }

    @Override
    public Role findByRoleName(String role_name) throws Exception {
        return roleMapper.findByRoleName(role_name);
    }

    @Override
    public List<Role> roles() throws Exception {
        return roleMapper.roles();
    }

    @Override
    public int insert(Role role) throws Exception {
        Role roleName = findByRoleName(role.getRole_name());
        return null == roleName ? roleMapper.add(role) : -1;
    }

    @Override
    public Role findById(long id) throws Exception {
        return roleMapper.findById(id);
    }
}
